<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%> 
<html>
<style type="text/css">
pre {
	white-space: pre-wrap;
	word-wrap: break-word;
}
</style>
<head>
		<meta charset="utf-8" />
		<meta name="keywords" content="pinpin社保" />
		<meta name="description" content="pinpin社保" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
        <meta name="renderer" content="webkit" />
        <meta name="viewport" content="width=device-width, initial-scale=1">
		<title>社保运营后台-政务内容</title>
		<link rel="stylesheet" href="/as/css/bootstrap.css" />
		<link rel="stylesheet" href="/as/css/layout.css" />
	<%@ include file="/WEB-INF/jsp/common/common.jsp" %>
</head>
<body>
	<div id="wrapper">
		<%@ include file="/WEB-INF/jsp/common/menu.jsp" %>
        <!-- Page Content -->
        <div id="page-wrapper">
        	<div class="row">
                <div class="col-lg-12">
                    <!-- 路径导航 -->
                    <ol class="breadcrumb">
				      <li><a href="${list_uri }">政务内容列表</a></li>
				    </ol>
                </div>
            </div>
            <div class="row">
                <div class="col-lg-12">
                    <div class="panel panel-default">
                        <div class="panel-heading">
							<label>配置内容主数据  </label>
						</div>
                        <div class="panel-body">
	                        <form id="form0" class="form-horizontal" action="${setting_uri }" role="form" method="POST">
			                   	<input type="hidden" name="id" value="${id }">
			                   	<input type="hidden" name="batchNo" id="batchNo" value="${data.batchNo }">
                               	<div class="form-group">
		                   			<label class="col-md-1 control-label">禁用:</label>
                                    <div class="col-md-3">
                                    	<label class="checkbox-inline"><input type="radio" name="disabled" value="0" <c:if test="${!data.disabled }">checked</c:if> >否</label>
                                        <label class="checkbox-inline"><input type="radio" name="disabled" value="1" <c:if test="${data.disabled }">checked</c:if> >禁用</label>
			                    	</div>
		                   			<label class="col-md-1 control-label">常见问题:</label>
                                    <div class="col-md-3 form-inline">
                                        <label class="checkbox-inline"><input type="radio" name="hot" value="0" <c:if test="${data.hot==0 }">checked</c:if>>否</label>
                                        <label class="checkbox-inline"><input type="radio" name="hot" value="1" <c:if test="${data.hot==1 }">checked</c:if>>是</label>
			                    	</div>
		                   			<label class="col-md-1 control-label">显示顺序:</label>
                                    <div class="col-md-2">
						                <input type="number" name="hotSeq" id="hotSeqId"  value="${data.hotSeq }" class="form-control" placeholder="请填写">
			                    	</div>
			                    </div>
	                        	<div class="form-group">
	                        		<label class="col-md-1 control-label">类型:</label>
                                    <div class="col-md-3">
						                <select name="typeId" class="form-control">
						                	<c:forEach items="${typeList }" var="typeItem">
			                        		<option value="${typeItem.id}" <c:if test="${data.typeId==typeItem.id }">selected</c:if> >${typeItem.typeName}</option>
			                        		</c:forEach>
			                        	</select>
			                    	</div>
		                   			<label class="col-md-1 control-label">标题:</label>
			                        <div class="col-md-6">
        			    				<input type="text" name="title"  value="${data.title }" class="form-control" placeholder="请填写">
			                        </div>
	                        	</div>
	                        	<div class="form-group">
		                   			<label class="col-md-1 control-label">城市:</label>
			                        <div class="col-md-11">
        			    				<input type="text" name="city" id="citysVal" value="${data.city }" readOnly class="form-control" style="margin-bottom: 10px" placeholder="请选择" onclick="javascript:$('#pcityDiv').toggle();$('#cityDiv').toggle();">
			                        	<div class="alert alert-info" id="pcityDiv" style="display:none">
        			    				</div>
        			    				<div class="alert alert-info" id="cityDiv" style="display:none">
        			    				</div>
			                        </div>
	                        	</div>
                               	<div class="form-group">
	                        	</div>
	                        	<div class="form-group">
		                   			<label class="col-md-9 control-label"><c:if test="${data.batchNo > 0}"><span class="text-warning">关联城市：(<c:forEach items="${batchCity}" var="bc">${bc } </c:forEach>)</span></c:if></label>
		                   			<c:if test="${data.batchNo > 0 }">
		                            <div class="col-md-1">
		                            	<input type="button" onclick="settingBatch(this)"  value=" 关 联  保 存  " class="btn btn-outline btn-primary" >
		                            </div>
		                            </c:if>
		                   			<div class="col-md-1">
		                            	<input type="button" onclick="settingCurr(this)"   value=" 保 存 " class="btn btn-outline btn-info" >
		                            </div>
	                        	</div>
			                </form>
                        </div>
                        <!-- /.panel-body -->
                    </div>
                    <!-- /.panel -->
                </div>
            </div>
            <c:if test="${id > 0 }">
            <div class="row">
                <div class="col-lg-12">
                	<c:set var="cIndex" value="0"></c:set>
                    <c:forEach items="${data.content }" var="r">
                      	<table class="table no-footer">
                            	<tr role="row" >
                            		<td width="200px" style="border-top:0px"></td>
                            		<td id="subT${cIndex }" class="info" style="text-align:center">${r.t }</td>
                            		<td width="200px" style="border-top:0px"><a href="javascript:toEdit(${cIndex })">编辑</a> | 
                            			<c:if test="${cIndex > 0}"><a id="m1" href="javascript:moveCurr('m1', ${cIndex })">上移</a>
                            				<c:if test="${data.batchNo > 0 }"><a id="m2" href="javascript:moveBatch('m2', ${cIndex })"> | 关联上移</a></c:if>
                            			</c:if>
                            		</td>
                                </tr>
                                <tr role="row">
                            		<td width="200px" style="border-top:0px"></td>
                            		<td><pre id="subC${cIndex }">${r.c }</pre></td>
                            		<td width="200px" style="border-top:0px"></td>
                                </tr>
                        </table>
                        <c:set var="cIndex" value="${cIndex + 1 }"></c:set>
                   </c:forEach>
                </div>
            </div>
            <div class="row">
                <div class="col-lg-12">
                    <div class="panel panel-default">
                        <div class="panel-heading">
							<label id="tLabelId">配置内容数据</label>
						</div>
                        <div class="panel-body">
	                        <form id="formc" class="form-horizontal" action="${setting_c_uri }" role="form" method="POST">
			                   	<input type="hidden" name="id" value="${id }">
			                   	<input type="hidden" name="editIndex" id="editIndex" value="-1">
			                   	<input type="hidden" name="batchNo" id="cbatchNo" value="${data.batchNo }">
	                        	<div class="form-group">
	                        		<label class="col-md-1 control-label">小标题:</label>
			                        <div class="col-md-11">
			                        	<input type="text" name="subTitle" id="subTitleId" value="" class="form-control" placeholder="请填写">
			                        </div>
	                        	</div>
                               	<div class="form-group">
		                   			<label class="col-md-1 control-label">小内容:</label>
			                        <div class="col-md-11">
        			    				<textarea name="subContent" id="subContentId" rows="10" cols="" class="form-control"></textarea> 
			                        </div>
	                        	</div>
                               	<div class="form-group">
	                        	</div>
	                        	<div class="form-group">
		                   			<label class="col-md-8 control-label"></label>
		                   			<c:if test="${data.batchNo > 0 }">
		                            <div class="col-md-2">
		                            	<input type="button" onclick="settingBatchContent(this)"  value=" 关 联 配 置 内 容  " class="btn btn-outline btn-primary" >
		                            </div>
		                            </c:if>
		                   			<div class="col-md-1">
		                            	<input type="button" onclick="settingCurrContent(this)"  value=" 配 置 内 容 " class="btn btn-outline btn-info" >
		                            </div>
		                            <div class="col-md-1">
		                            	<input type="button" onclick="toAdd()"  value=" 重置 " class="btn btn-outline btn-primary" >
		                            </div>
	                        	</div>
			                </form>
                        </div>
                        <!-- /.panel-body -->
                    </div>
                    <!-- /.panel -->
                </div>
            </div>
            </c:if>
        </div>
        <!-- /#page-wrapper -->
    </div>
    <!-- /#wrapper -->
</body>
<script src="/as/js/province.js"></script>
<script src="/as/js/city.js"></script>
<script type="text/javascript">
var setting_uri = "${setting_uri}";
var setting_c_uri = "${setting_c_uri}";
var setting_move_uri = "${setting_move_uri}";

$(function () {
	initPcity("pcityDiv", "pcity", "cityDiv", "checkbox", "citys");
});

function settingBatch(btnObj) {
	btnConfirm(btnObj, "确定关联数据？", "关联更改多城市的数据。不更新城市字段。", function(){
		$("#form0").submit();
	});
}

function settingCurr(btnObj) {
	if ($("#batchNo").val() > 0) {
		btnConfirm(btnObj, "确定只变更当前城市数据？", "处理后自动解除关联。", function(){
			$("#batchNo").val("-1"); // 解除关联
			$("#form0").submit();
		});
	} else {
		$("#form0").submit();
	}
}

function settingBatchContent(btnObj) {
	if ($("#batchNo").val() > 0) {
		btnConfirm(btnObj, "确定关联数据？", "关联变更对应段落的内容。", function(){
			settingContent();
		});
	}
}
function settingCurrContent(btnObj) {
	if ($("#batchNo").val() > 0) {
		btnConfirm(btnObj, "确定只更新当前城市的数据？", "<li>本次设置内容可以多城市关联改动</li> <li>执行成功后将自动解除关联</li>", function(){
			$("#cbatchNo").val("-1"); // 解除关联
			settingContent();
		});
		return;
	}
	settingContent();
}

function settingContent() {
	var data = $("#formc").serialize();
	$.post(setting_c_uri, data, function(ret,status){
		if (ret.code==200) {
			iRun(ret.msg, 1, function(){
				window.location.reload();
			});
		} else {
			notice(ret.code + "  " + ret.msg);
		}
	});
}

function toAdd(){
	$("#tLabelId").text("配置 内容");
	$("#editIndex").val("-1");
	$("#subTitleId").val("");
	$("#subContentId").val("");
}

function toEdit(index) {
	$("#subTitleId").val($("#subT"+index).html());
	$("#subContentId").val($("#subC"+index).html());
	$("#editIndex").val(index);
	$("#subContentId").focus();
	$("#tLabelId").text("配置 【" + $("#subTitleId").val()+" 】的内容");
}

function moveBatch(eid, index) {
	iConfirm(eid, "确定关联数据？", "确定移动多个城市的此段数据？", function(){
		move(index);
	});
}
function moveCurr(eid, index) {
	if ($("#batchNo").val() > 0) {
		iConfirm(eid, "确定？", "确定仅仅移动当前城市的此段数据？将解除关联。", function(){
			$("#cbatchNo").val("-1"); // 解除关联
			move(index);
		});
		return;
	}
	move(index);
}
function move(index) {
	$("#editIndex").val(index);
	$("#subTitleId").val("");
	$("#subContentId").val("");

	var data = $("#formc").serialize();
	$.post(setting_move_uri, data, function(ret,status){
		if (ret.code==200) {
			iRun(ret.msg, 1, function(){
				window.location.reload();
			});
		} else {
			notice(ret.code + "  " + ret.msg);
		}
	});
}
	
</script>
</html>